//
//  ViewController.m
//  10802homework
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (weak, nonatomic) IBOutlet UIButton *btnPressed;
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
@property (weak, nonatomic) IBOutlet UILabel *infoLable;
@property(nonatomic,strong)NSArray *leftlist;
@property(nonatomic,strong)NSArray *rightlist;
- (IBAction)btnPressed:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.leftlist = @[@"火腿",@"火鸡",@"花生酱",@"水果沙拉",@"时令果盘",@"酱牛肉",@"鸭胗",@"佛跳墙",@"蚂蚁上树",@"龙虎斗"];
    self.rightlist = @[@"白面包",@"粗面粉面包",@"黑麦面包",@"五彩燕麦面包",@"旺仔小馒头",@"东坡肉",@"西施豆腐",@"老婆饼",@"麦香鸡块"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnPressed:(id)sender
{
    int sel1 = [self.pickerView selectedRowInComponent:0];
    int sel2 = [self.pickerView selectedRowInComponent:1];
    
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"你选择了%@和%@",self.leftlist[sel1],self.rightlist[sel2]]   delegate:self cancelButtonTitle:@"重新选择" otherButtonTitles:@"确定",nil];
    
    [alert show];
    self.infoLable.text = [NSString stringWithFormat:@"我的早饭是%@和%@",self.leftlist[sel1],self.rightlist[sel2]];
    
    
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftlist.count;
    }
    else
    {
        return self.rightlist.count;
    }
}
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftlist[row];
    }
    else
    {
        return self.rightlist[row];
    }
    
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(component == 0)
    {
        NSLog(@"当前你选择了%@",self.leftlist[row]);
    }
    else
    {
        NSLog(@"当前你选择了%@",self.rightlist[row]);    }
    
    self.btnPressed.titleLabel.text = [NSString stringWithFormat:@"选择%@和%@",self.leftlist[row],self.rightlist[row]];
}

@end
